package com.xhl.lk.auth2.modules.admin.demo;
import org.redisson.Redisson;
import org.redisson.api.RBloomFilter;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;

public class RedissonBloomFilterExample {
    public static void main(String[] args) {
        // 创建Redisson客户端
        Config config = new Config();
        config.useSingleServer().setAddress("redis://192.168.245.181:6379");
        config.useSingleServer().setPassword("508816");
        RedissonClient redisson = Redisson.create(config);

        // 创建Bloom Filter
        RBloomFilter<String> bloomFilter = redisson.getBloomFilter("bloomFilter");
        // 初始化Bloom Filter，预计容量为10000，误判率为0.01
        bloomFilter.tryInit(10000L, 0.01);

        // 添加元素到Bloom Filter
        bloomFilter.add("element1");
        bloomFilter.add("element2");

        // 检查元素是否存在于Bloom Filter
        System.out.println(bloomFilter.contains("element1")); // true
        System.out.println(bloomFilter.contains("element3")); // false

        // 关闭Redisson客户端
        redisson.shutdown();
    }
}
